import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
// export default defineConfig({
//   plugins: [vue()],
// })
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';


import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig(({ mode, command, ssrBuild }) => {
  const env = loadEnv(mode, process.cwd())
  console.log(env)
  return {
    base: './',
    envDir: resolve(__dirname, 'env'),
    plugins: [
      vue(),
      Components({
        resolvers: [[AntDesignVueResolver({importStyle: "less"})]],
      }),
    ],
    resolve:{
      alias: [
        {
          find: "@",
          replacement: resolve(__dirname, 'src')
        }
      ]
    },
    server: {
      port: 8080, //启动端口
      // hmr: {
      //   host: 'localhost',
      //   port: 8080
      // },
      proxy: {
        [env.VITE_API_URL]: {
          target: 'http://localhost:8081/',
          changeOrigin: true,
          // rewrite: (path: string) => path.replace(/^\/api/, '')
          rewrite: path => path.replace(RegExp(`^${env.VITE_API_URL}`), '')
        }
      }
    },
  }
}
  
)
